<?php
        if(!(isset($_GET['begin']) && isset($_GET['offset']))) die('Error!');
        $begin = $_GET['begin'];
        $offset = $_GET['offset'];
        $cut = (isset($_GET['cut'])) ? $_GET['cut'] : "198001";
        $toload = $begin + $offset;
        $urls = array("1.php","2.php","3.php","4.php","5.php","meerdata.php");
        $collection = array();
        $return = array();
        foreach($urls as $url)
        {
                $single = json_decode(file_get_contents($url))
                        or die('Couldn\'t decode data');
                $collection = array_merge($collection, $single);
        }
        $id = 0;
        foreach($collection as $item)
        {
                preg_match_all('/([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $item->start, $matches);
                $curTime = $matches[1][0] . $matches[2][0];
                if($curTime < $cut) unset($collection[$id]);
                $id++;
        }
        $collection.usort($collection, "sortDate");
        $load = (count($collection) > $toload) ? $toload : count($collection);
        for($i = $begin; $i < $load;)
        {
                $return[] = $collection[$i];
                $i++;
        }

        echo json_encode($return);

        function sortDate($a, $b)
        {
                return $a->start > $b->start;
        }